/*
 *  Copyright 2011 yura.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */
package org.opu.db_vdumper.ui.component.tabel.models;

import org.opu.db_vdumper.beans.ColumnBean;
import org.opu.db_vdumper.ui.component.tabel.views.ArrowView;

/**
 *  Arrow model combines two {@link TableModel}
 * @author Potochnak Yana
 */
public class ArrowModel extends Model<ArrowView> {

    public static int DEFAULT_LINE = 0;
    public static Pike DEFAULT_PIKE = new Pike(45, 5);

    /** model to calling repaint from table */
    private TableModel fromModel;

    /** model to calling repaint from table */
    private TableModel toModel;

    
    /** From which the attribute connection */
    private ColumnBean from; //от которого

    /** To which the attribute connection */
    private ColumnBean to;   //к кому


    /** Start of line */
    private Pike startPike;//наконечник стрелы

    /** End of line */
    private Pike endPike;//наконечник стрелы


    /** Type of line */
    private int lineType;

    public ArrowModel(TableModel fromModel, TableModel toModel, ColumnBean from,
            ColumnBean to, Pike startPike, Pike endPike, int lineType) {

        this.fromModel = fromModel;
        this.toModel = toModel;
        this.from = from;
        this.to = to;
        this.startPike = startPike;
        this.endPike = endPike;
        this.lineType = lineType;

        this.fromModel.addArrowModel(ArrowModel.this);
        this.toModel.addArrowModel(ArrowModel.this);
    }

    public ArrowModel(TableModel fromModel, TableModel toModel, ColumnBean from, ColumnBean to) {
        this(fromModel, toModel, from, to, DEFAULT_PIKE, DEFAULT_PIKE, DEFAULT_LINE);
    }

    public TableModel getFromModel() {
        return fromModel;
    }

    public TableModel getToModel() {
        return toModel;
    }

    public ColumnBean getFrom() {
        return from;
    }

    public int getLineType() {
        return lineType;
    }

    public void setLineType(int lineType) {
        this.lineType = lineType;
    }

    public ColumnBean getTo() {
        return to;
    }

    public Pike getEndPike() {
        return endPike;
    }

    public void setEndPike(Pike endPike) {
        this.endPike = endPike;
    }

    public Pike getStartPike() {
        return startPike;
    }

    public void setStartPike(Pike startPike) {
        this.startPike = startPike;
    }

    public void revalidate() {
        for (ArrowView r : views) {
            r.reinit();
        }
    }

    @Override
    public boolean hasChildrens() {
        return false;
    }
}
